﻿using MediatR;
using Production_Set.API.Application.Commands.Resourctes;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Customers;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.Application.Commands.Customerser
{
    /// <summary>
    /// 客户删除
    /// </summary>
    public class CustomerDeleteHandler : IRequestHandler<CustomerDeleteCommend, Result>
    {
        private readonly IBaseRepository<Customer> Customer;

        public CustomerDeleteHandler(IBaseRepository<Customer> Customer)
        {
            this.Customer = Customer;
        }

        public async Task<Result> Handle(CustomerDeleteCommend request, CancellationToken cancellationToken)
        {
            var results = new Result() { Code = (int)CommonErrorCodes.Delete };

            string sql = "UPDATE Customer SET IsDelete=1 WHERE CustomerId=" + request.CustomerId;
            var list = Customer.Update(sql, results);
            if (list != null)
            {
                results.Code = (int)CommonErrorCodes.Success;
                results.Msg = "删除成功";
            }

            return results;
        }
    }
}
